//
// Created by jiangpenghui on 2023/4/14.
//

#include "NumStringGen.h"

#include <mutex>
#include <execution>

bool twice(int ele1, int ele2) {

    return ele1 * 2 == ele2;

}

void adjacent_find_test() {
    using namespace std;
    list<int> L;
    list<int>::iterator Iter;
    list<int>::iterator result1, result2;
    L.push_back(20);
    L.push_back(30);
    L.push_back(12);
    L.push_back(45);
    L.push_back(13);
    L.push_back(56);

    L.push_back(50);
    L.push_back(40);
    L.push_back(10);
    L.push_back(20);
    L.push_back(20);
    cout << "L = (";
    for (Iter = L.begin(); Iter != L.end(); Iter++)
        cout << *Iter << " ";
    cout << ")" << endl;

    result1 = adjacent_find(L.begin(), L.end());
    if (result1 == L.end())
        cout << "There are not two adjacent elements that are equal."
             << endl;
    else
        cout << "There are two adjacent elements that are equal.\n"
             << "They have a value of "
             << *(result1) << "." << endl;


    result2 = adjacent_find(L.begin(), L.end(), twice);
    if (result2 == L.end())
        cout << "There are not two adjacent elements where the "
             << "second is twice the first." << endl;
    else {
        cout << "There are two adjacent elements where "
             << "the second is twice the first.\n"
             << "They have values of " << *(result2++)
             << " & " << *result2 << "." << endl;
    }
}

void all_of_test() {
    using namespace std;
    list<int> li{50, 41, 12, 20, 20};

    cout << "li = (";
    for (list<int>::iterator iter = li.begin(); iter != li.end(); iter++)
        cout << *iter << " ";
    cout << " )" << endl;
    // lambda 表达式 入参 elem 出参 bool
    auto is_even = [](int elem) { return !(elem % 2); };

    if (all_of(li.begin(), li.end(), is_even))
        cout << "All the elements are even numbers.\n";
    else
        cout << "Not all the elements are even numbers.\n";

}

// 元素范围内
void clamp_test() {
    list<int> li{50, 41, 12, 20, 20};
    // 三元表达式  value 小于 low 返回low  大于upper返回upper
    int result = clamp(23, 20, 30);
    cout << result << endl;
}

bool mod_lesser(int ele1, int ele2) {

    if (ele1 < 0)
        ele1 = -ele2;
    if (ele2 < 0)
        ele2 = -ele2;
    return ele2 < ele2;

}

void includes_test() {
    vector<int> v1(100);
    vector<int> v2(100);
    generate(v1.begin(), v1.end(), rand);
    generate(v2.begin(), v2.end(), rand);


    // int 类型排序    { return __x > __y; } 降序  less<int> 升序
    sort(v1.begin(), v1.end(), less<int>());
    sort(v2.begin(), v2.end(), less<int>());

    cout << "v1 = (";
    for (vector<int>::iterator iterator = v1.begin(); iterator != v1.end(); iterator++)
        cout << *iterator << " ";
    cout << ")." << endl;

    cout << "v2 = (";
    for (vector<int>::iterator iterator = v2.begin(); iterator != v2.end(); iterator++)
        cout << *iterator << " ";
    cout << ")." << endl;


    int result = includes(v2.begin(), v2.end(), v1.begin(), v1.end(), less<int>());
    cout << "v2 is includes v1 " << boolalpha << result << endl;
}

void algorithm_swap() {
    using namespace std;
    vector<int> v1(100);
    vector<int> v2(100);
    generate(v1.begin(), v1.end(), rand);
    generate(v2.begin(), v2.end(), rand);
    swap(v1,v2);
}
